/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hdasnvicpaul.manager;

import com.hdasnvicpaul.entidad.Anciano;
import java.math.BigDecimal;
import java.math.BigInteger;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author WILLIAN
 */
@Stateless
public class AncianoFacade extends AbstractFacade<Anciano> implements AncianoFacadeLocal {

    @PersistenceContext(unitName = "HdASntVicPaul-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public AncianoFacade() {
        super(Anciano.class);
    }

    public Integer getCorrelativo() {
        BigDecimal c = new BigDecimal("0");
        Query query = getEntityManager().createNativeQuery("select nvl(count(*), 0) as correlativo from ANCIANO");
        //query.setParameter("institucion", 1);
        //query.setParameter("sucursal", 1);
        c = (BigDecimal) query.getSingleResult();
        return c == null ? 1 : c.intValue();
    }
}
